import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { ScmPurchaseOrder } from "@/pages/wms/po/entity";

interface SinglePurchaseOrderSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedPurchaseOrder?: ScmPurchaseOrder) => void;
}

const SinglePurchaseOrderSelect: React.FC<SinglePurchaseOrderSelectorProps> = ({ open, onCancel, onOk }) => {
	// 选中的采购订单
	const [selectedPurchaseOrder, setSelectedPurchaseOrder] = useState<ScmPurchaseOrder>();

	const handleOk = () => {
		onOk(selectedPurchaseOrder);
	};

	return (
		<Modal title="选择采购订单" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable
				reportCode="receive_po_selector"
				selectionType={SelectionType.RADIO}
				onSelectChange={(selectedRows) => {
					setSelectedPurchaseOrder(selectedRows[0]);
				}}
			/>
		</Modal>
	);
};

export default SinglePurchaseOrderSelect;
